<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="keywords" content="美食,团购,外卖,网上订餐,酒店,旅游,电影票,火车票,飞机票">
    <meta name="description" content="美食攻略,外卖网上订餐,酒店预订,旅游团购,飞机票火车票,电影票,ktv团购吃喝玩乐全都有!店铺信息查询,商家评分/评价一站式生活服务网站">
    <title>{$setting['title']}</title>
    <link rel="stylesheet" href="{RES}/plugin/light7/light7.min.css">
    <link rel="stylesheet" type="text/css" href="{php echo $this->cur_mobile_path}/css/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="{php echo $this->cur_mobile_path}/css/api.css"/>
    <link rel="stylesheet" type="text/css" href="{php echo $this->cur_mobile_path}/css/common.css"/>
    <link rel="stylesheet" href="{php echo $this->cur_mobile_path}/css/shop.css?v=5">
    <link rel="stylesheet" type="text/css" href="{php echo $this->cur_mobile_path}/css/fakeLoader.css">
    <script src="{php echo $this->cur_mobile_path}/script/jquery-1.8.3.min.js"></script>
    <style>
        i {
            width: 12px;
            height: 12px;
            display: inline-block;
            line-height: 12px;
            font-size: 12px;
            margin-right: 2px;
            text-align: center;
            color: #fff;
            border-radius: 2px;
        }
        .icon-bg1{ background:#70bc46;}
        .icon-bg2{ background:#f07373;}
        .icon-bg3{ background:#f1884f;}
        .icon-bg4{ background:#f5a317;}
        .info {
            font-size: 10px;
            color: #a7a2a9;
        }
        .icon-delivery {
            padding: 0 1px;
        border: 1px solid {$setting['style_base']};
        border-radius: 2px;
        background-color: #fff;
        color: {$setting['style_base']};
        font-size: 10px;
        line-height: 12px;
        }
        .footer-bar.bar-tab .tab-item.active .icon, .bar-tab .tab-item:active .icon {
        color: {$setting['style_base']};
        }
        .footer-bar.bar-tab .tab-item.active, .bar-tab .tab-item:active {
        color: {$setting['style_base']};
        }
    </style>
</head>
<body>
<div class="fakeloader"></div>
{php $url_search = $this->createMobileUrl('search', array(), true);}
{php $url_user = $this->createMobileUrl('usercenter', array(), true);}
<div id="wrap" style="height:100%;overflow: scroll;overflow-y:scroll;-webkit-overflow-scrolling:touch;">
    <div id="header" style="background-color: {$setting['style_base']};border-bottom: 1px solid {$setting['style_base']};">
        <div class="search" tapmode="topbar-active" onclick="javascript:window.location.href='{$url_search}'">
            <i class="i-search"></i>
        </div>
        <div class="flex-full">商家列表</div>
        <div class="map" tapmode="topbar-active"  onclick="javascript:window.location.href='{$url_user}'">
            <i class="i-user"></i>
        </div>
    </div>
    <span class="filter">
        <div class="filter-header">
            <a class="filter-nav" href="javascript:" data-value="0">
                <span>{$curtype}</span><i class="i-up"></i>
            </a>
            <a class="filter-nav" href="javascript:"  data-value="0">
                <span>{$curarea}</span><i class="i-up"></i>
            </a>
            <a class="filter-nav filter-nav-more" href="javascript:" data-value="0">
                <span>{$cursort}</span><i class="i-up"></i>
            </a>
        </div>
        <section class="filter-extend filter-category">
            <div class="filter-scroller">
                <ul class="shoptype">
                    <li data-id="0" {if $typeid == 0}class="active"{/if}>
                        <span>门店类型</span>
                        <i class="i-right"></i>
                    </li>
                    {loop $shoptype $item}
                    <li data-id="{$item['id']}"  {if $typeid ==  $item['id']}class="active"{/if}>
                        <span>{$item['name']}</span>
                        <i class="i-right"></i>
                    </li>
                    {/loop}
                </ul>
            </div>
        </section>
        <section class="filter-extend filter-sort">
            <ul class="areatype">
                <li {if $areaid == 0}class="active"{/if} data-id="0">
                    <span>全城</span>
                    <i class="i-right"></i>
                </li>
                {loop $area $item}
                <li {if $areaid == $item['id']} class="active"{/if}  data-id="{$item['id']}">
                    <span>{$item['name']}</span>
                    <i class="i-right"></i>
                </li>
                {/loop}
            </ul>
        </section>
        <section class="filter-extend filter-more">
            <ul class="shopsort">
                <li {if $sortid == 0}class="active"{/if} data-id="0">
                    <span>
                        综合排序
                    </span>
                </li>
                <li data-id="1" {if $sortid == 1}class="active"{/if}>
                    <span>
                        正在营业
                    </span>
                </li>
                <li data-id="2" {if $sortid == 2}class="active"{/if}>
                    <span>
                        距离优先
                    </span>
                </li>
            </ul>
        </section>
    </span>
    <div id="main" style="margin-top:84px;padding-bottom: 70px;">
        <div class="box item-list" id="index-data">
            {loop $restlist $item}
            {if $item['default_jump']==1}
            {php $url = $this->createMobileUrl('detail', array('id' => $item['id'], 'sid' => $sid), true);}
            {elseif $item['default_jump']==2}
            {php $url = $this->createMobileUrl('waplist', array('storeid' => $item['id'], 'mode' => 2, 'sid' => $sid), true);}
            {elseif $item['default_jump']==3}
            {php $url = $this->createMobileUrl('waplist', array('storeid' => $item['id'], 'mode' => 4, 'sid' => $sid), true);}
            {elseif $item['default_jump']==4}
            {php $url = $this->createMobileUrl('queue', array('storeid' => $item['id'], 'sid' => $sid), true);}
            {elseif $item['default_jump']==5}
            {php $url = $this->createMobileUrl('reservationIndex', array('storeid' => $item['id'], 'mode' => 3, 'sid' => $sid), true);}
            {elseif $item['default_jump']==6}
            {php $url = $item['default_jump_url'];}
            {/if}
            <section class="item" onclick="location.href='{$url}'">
                <div class="left-wrap">
                    <img class="logo lazy" data-original="{php echo tomedia($item['logo']);}" src="{php echo tomedia($item['logo']);}" onerror="this.src='{php echo tomedia('./addons/weisrc_dish/icon.jpg');}'">
                    {if $this->getstoretimestatus($item) == 0}
                    <span class="status-tip" style="background-color: rgb(192, 192, 192);"> 商家休息 </span>
                    {/if}
                </div>
                <div class="right-wrap">
                    <section class="line">
                        <h3 class="shopname">
                            {if $item['is_brand']==1}<span class="premium">{$item['brandname']}</span>{/if}
                            {$item['title']}
                        </h3>
                        <div class="support-wrap">
                            {if $item['is_meal']==1}
                            <div class="activity-wrap nowrap">
                                <i class="activity-icon icononly"
                                   style="color: rgb(153, 153, 153); border-color: rgb(221, 221, 221);"> 店 </i>
                            </div>
                            <div class="tag label-red ng-scope"></div>
                            {/if}
                            {if $item['is_delivery']==1}
                            <div class="activity-wrap nowrap">
                                <i class="activity-icon icononly"
                                   style="color: rgb(153, 153, 153); border-color: rgb(221, 221, 221);"> 外 </i>
                            </div>
                            {/if}
                        </div>
                    </section>
                    <section class="line">
                        <div class="rate-wrap">
                       	<span>
                            <?php for($i=0;$i < $item['level']; $i++){ ?>
                            <i class="i-star i-star-gold"></i>
                            <?php }?>
                            <!--<i class="i-star i-star-gold"></i>-->
                            <!--<i class="i-star i-star-gold"></i>-->
                            <!--<i class="i-star i-star-gold"></i>-->
                            <!--<i class="i-star i-star-gray">-->
                                <!--<i class="i-star i-star-gold"></i>-->
                            <!--</i>-->
                            <!--<i class="i-star i-star-gray"></i>-->
                        </span>
                            <!--<span class="rate">4.6</span>-->
                            {if $item['sales']>0}
                            <span>已售{$item['sales']}份</span>
                            {/if}
                        </div>
                        <div class="delivery-wrap">
                            <span class="icon-delivery">
                                {if $item['is_delivery']==1}
                                准时达
                                {else}
                                商家联盟
                                {/if}
                            </span>
                        </div>
                    </section>
                    <section class="line">
                        <div class="moneylimit">
                            {if $item['is_delivery']==1}
                            {if !empty($item['sendingprice'])}
                            <span>{$setting['currency']}{$item['sendingprice']}起送</span>
                            {/if}
                            {if $item['dispatchprice']>0}
                            <span>配送费约{$setting['currency']}{$item['dispatchprice']}</span>
                            {else}
                            <span>免配送费</span>
                            {/if}
                            {if $item['freeprice']!=0.00}
                            <span>满{php echo intval($item['freeprice'])}免配送费</span>
                            {/if}
                            {else}
                            <span>{$item['address']}</span>
                            {/if}
                        </div>
                        <div class="timedistance-wrap">
                            <span class="distance-wrap">{php echo $this->getDistance($item['lat'], $item['lng'], $lat, $lng).'km';}</span>
                            {if $item['deliverytime'] > 0}
                            <span class="time-wrap">{$item['deliverytime']}分钟</span>
                            {/if}
                        </div>
                    </section>
                    {if !empty($item['newlimitprice'])}
                    <section class="line">
                        <div>
                            <i class="icon-bg1">新</i><span class="info">{$item['newlimitprice']}</span>
                        </div>
                    </section>
                    {/if}
                    {if !empty($item['oldlimitprice'])}
                    <section class="line">
                        <div>
                            <i class="icon-bg2">减</i><span class="info">{$item['oldlimitprice']}</span>
                        </div>
                    </section>
                    {/if}
                </div>
            </section>
            {/loop}
        </div>
        <div class="popup-overlay"></div>
        <!--<div class="top-btn" style="display: block;">-->
            <!--<a class="react">-->
                <!--<i class="text-icon">⇧</i>-->
            <!--</a>-->
        <!--</div>-->
        <input type="hidden" id="curlat" name="curlat" value="0"/>
        <input type="hidden" id="curlng" name="curlng" value="0"/>
        <input type="hidden" id="isposition" name="isposition" value="{$isposition}" />
        <input type="hidden" id="cururl" name="cururl" value="{php echo $this->createMobileurl('waprestlist', array('typeid' => $typeid,'areaid' => $areaid, 'sortid' => $sortid), true)}" />

        <script>
            //top行为
//            $('.top-btn').on('click',function(){
//                $("html, body").animate({ scrollTop: 0 }, "slow");
//            });
//            if ($(document).scrollTop() == 0) {
//                $('.top-btn').css('display','none');
//            }
//            $(document).bind('scroll',function() {
//                if ($(document).scrollTop() == 0) {
//                    $('.top-btn').css('display','none');
//                }else{
//                    $('.top-btn').css('display','block');
//                }
//            })
        </script>
        <script type="text/javascript">
            //区域
            $('.areatype > li').click(function () {
                var curlat = $('#curlat').val();
                var curlng = $('#curlng').val();
                var id = $(this).attr("data-id");

                window.location.href = "{php echo $this->createMobileurl('waprestlist', array('storeid' => $storeid, 'sortid' => $sortid, 'typeid' => $typeid), true)}" + '&areaid=' + id + '&lat=' + curlat + '&lng=' + curlng;
            });
            //商家类型
            $('.shoptype > li').click(function () {
                var curlat = $('#curlat').val();
                var curlng = $('#curlng').val();
                var id = $(this).attr("data-id");
                window.location.href = "{php echo $this->createMobileurl('waprestlist', array('storeid' => $storeid, 'sortid' => $sortid, 'areaid' => $areaid), true)}" + '&typeid=' + id + '&lat=' + curlat + '&lng=' + curlng;
            });
            //排序
            $('.shopsort > li').click(function () {
                var curlat = $('#curlat').val();
                var curlng = $('#curlng').val();
                var id = $(this).attr("data-id");
                window.location.href = "{php echo $this->createMobileurl('waprestlist', array('storeid' => $storeid, 'typeid' => $typeid, 'areaid' => $areaid), true)}" + '&sortid=' + id + '&lat=' + curlat + '&lng=' + curlng;
            });
        </script>
    </div>
    <script>
        $(document).ready(function(e) {
            $('.filter-header .filter-nav').click(function(e) {
                var index=$(this).index()
                var datavalue=$(this).attr('data-value')//判断是否显示
                if(datavalue==1){
                    $('.filter-header .filter-nav').attr('data-value',0)
                    $(this).find('.i-up').css({"transform":"rotate(0deg)"})
                    $(this).find('span').removeClass('curt')
                    $('.filter-extend').eq(index).removeClass('open');
                    $('.popup-overlay').removeClass('modal-overlay-visible')
                }else{
                    $('.filter-header .filter-nav').attr('data-value',0)
                    $(this).attr('data-value',1)//判断是否显示
                    $('.filter-header .filter-nav span').removeClass('curt')
                    $(this).find('span').addClass('curt')
                    $('.filter-header .filter-nav').find('.i-up').css({"transform":"rotate(0deg)"})
                    $(this).find('.i-up').css({"transform":"rotate(180deg)"})
                    $('.filter-extend').removeClass('open')
                    $('.filter-extend').eq(index).addClass('open');
                    $('.popup-overlay').addClass('modal-overlay-visible')
                }
            });
        });
    </script>
</div>
{php echo register_jssdk(false);}
<script>
    wx.ready(function () {
        sharedata = {
            title: '{$share_title}',
            desc: '{$share_desc}',
            link: '{$share_url}',
            imgUrl: '{$share_image}',
            success: function(){
                //alert('感谢分享');
            },
            cancel: function(){
                //alert('cancel');
            }
        };
        wx.onMenuShareAppMessage(sharedata);
        wx.onMenuShareTimeline(sharedata);
        wx.getLocation({
            type: 'gcj02',
            success: function (res) {
                setPoint(res);
            },
            cancel: function (res) {
            },
            fail: function (res) {
//                alert(res);
            }
        });


    });
</script>
{php include $this->template($this->cur_tpl.'/_nave');}
<script type="text/javascript" src="{RES}/js/jquery.lazyload.min.js"></script>
<script>
    $(function () {
        $("img.lazy").lazyload({effect: "fadeIn"});
    });
</script>

<script type="text/javascript">
    var page = 2;
    var loading  = false;
    var stop_track = false;

    $(document).ready(function() {
        $('#wrap').scroll(function(){
            if ($(window).scrollTop() + $(window).height() == $(document).height()) {
                if(stop_track == false && loading==false) {
                    loading = true;
                    var loadurl ="{php echo $this->createMobileurl('getmorestore', array('areaid' => $areaid, 'typeid' => $typeid, 'sid' => $sid), true)}";
                    $.ajax({
                        type: 'POST',
                        url: loadurl,
                        data: {
                            'page': page
                        },
                        dataType: 'json',
                        timeout: 3000,
                        context: $('body'),
                        success: function(data){
                            if (data == '0') {
                                stop_track = true;
                            } else {
                                $("#index-data").append(data);
                                if (data == '') {
                                    stop_track = true;
                                }
//                                $('.animation_image').hide();
                                page++;
                                loading = false;
                            }
                        },
                        error: function (xhr) {
                            alert('网络通讯失败，请重试!');
                        }
                    });
                }
            }
        });
    });
</script>
<script>
    var HB_INWECHAT = "{php echo $this->isWeixin();}", mkey = "{$setting['qqmapapi']}", HS_MULTIUPLOAD = "1";
</script>
<script src="https://map.qq.com/api/js?v=2.exp&key={$setting['qqmapapi']}" type="text/javascript"></script>
<script src="{RES}/mobile/style1/script/geolocation.js?Dj8" type="text/javascript"></script>
<script>
    function distanceByLnglat(lng1, lat1, lng2, lat2) {
        var radLat1 = Rad(lat1);
        var radLat2 = Rad(lat2);
        var a = radLat1 - radLat2;
        var b = Rad(lng1) - Rad(lng2);
        var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
        s = s * 6378137.0;
        s = Math.round(s * 10000) / 10000000;
        s = s.toFixed(2);
        return s;
    }
    function setPoint(position){
        if(typeof position.type != 'undefined'){
            if(position.type == 'ip'){
                if(IGNORETIP){

                }else {
                    alert('无法定位当前点，请地图选点');
                    chooseMap(position);
                }
                return false;
            }
        }

        var lat = (position.latitude || position.lat);
        var lng = (position.longitude || position.lng);

        $(".morelist").each(function () {
            var ShopLngLat = $(this).find("#showlan").val();
            var InputOF = ShopLngLat.indexOf(",");
            var InputOFLast = ShopLngLat.length;
            var ShopLng = ShopLngLat.slice(0, InputOF);
            var ShopLat = ShopLngLat.slice(InputOF + 1, InputOFLast);
            var dist = distanceByLnglat(lng, lat, ShopLng, ShopLat);
            $(this).find("#shopspostion").html(dist + "km");
        });
        $("#curlat").val(lat);
        $("#curlng").val(lng);

        isposition = $("#isposition").val();
        cururl = $("#cururl").val();
        if (isposition == 0) {
            var url = cururl + '&lat=' + lat + '&lng=' + lng + '&pos=1';
            window.location = url;
        }
    }

    function he_getlocation(callback){
        console.log(typeof mag);
        if(HB_INWECHAT==0) {
            console.log('myapp');
            var geolocation = new qq.maps.Geolocation(mkey, "myapp");
            geolocation.getLocation(callback, function () {
            }, {timeout:4000, failTipFlag:true});
        }
    }
    he_getlocation(setPoint);
</script>
</body>
</html>
